﻿
using System.Text.Json.Serialization;

namespace Common.Page
{
    public class PageReq
    {
        /// <summary>
        /// 分页对象
        /// </summary>
        public BasePage? PageInfo { get; set; }
    }

    public class BasePage
    {
        /// <summary>
        /// 起始Id
        /// </summary>
        [JsonIgnore]
        public long IdGreaterEqual { get; private set; }

        /// <summary>
        /// 截至Id
        /// </summary>
        [JsonIgnore]
        public long IdLess { get; private set; }

        /// <summary>
        /// 创建时间(开始)
        /// </summary>
        public DateTime BeginTime
        {
            get => SnowFlakeHelper.ToTime(IdGreaterEqual);
            set
            {
                if (value==DateTime.MinValue)
                    value=DateTime.Now.AddDays(-3);
                
                IdGreaterEqual = SnowFlakeHelper.ToId(value);
            }
        }

        /// <summary>
        /// 创建时间(结束)
        /// </summary>
        public DateTime EndTime
        {
            get => SnowFlakeHelper.ToTime(IdLess).AddDays(-1);
            set
            {
                if (value==DateTime.MinValue)
                    value=DateTime.Today;
                IdLess = SnowFlakeHelper.ToId(value.AddDays(1));
            }
        }

        /// <summary>
        /// 页码
        /// </summary>
        public int PageIndex { get; set; }
        /// <summary>
        /// 每页数量
        /// </summary>
        public int PageSize { get; set; }

    }
}
